#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "getinfo.h"

int get_data(char *str)
{
	time_t timep;
	time(&timep);
	struct tm *p=localtime(&timep);
	sprintf(str,"DATA:%d/%d/%d/",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
	return 0;
}

int get_time(char *str)
{
	time_t timep;
	time(&timep);
	struct tm *p=localtime(&timep);
	
	sprintf(str,"TIME:%d:%d:%d:",(p->tm_hour),(p->tm_min),p->tm_sec);
	return 0;
}

int get_file_name(char *fname)
{
	int count=readlink("/proc/self/exe",fname,100);
	if(count<0|| count>100)
	{
		printf("Get File Name Error\n");
		return 1;
	}
    fname[count]=0;
	return 0;
}
int get_info(message_info*  msginf,int format[])
		
{
  int p=0;
  while(format[p]!=-1)
  {
	  if(format[p]==0)
      get_data(msginf->data);
	  else if(format[p]==1)
	get_time(msginf->time);
	  else if(format[p]==2)
		get_file_name(msginf->file_name);
	  p++;
  }

  return 0;

}


